package org.agile.grenoble.resources;

import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import javax.ws.rs.QueryParam;

import org.agile.grenoble.data.xml.QuestionsReader;
import org.agile.grenoble.questions.QuestionsDocument;


/**
 * commentaire
 */
@Path("/questions")
public class QuestionsResource {

	   // The Java method will process HTTP GET requests
       @GET 
       // The Java method will produce content identified by the MIME Media
       // type "text/plain"
       @Produces("text/xml")
       public String getClichedMessage(@QueryParam("all") boolean all, @QueryParam("getNumber") boolean getNumber) {
           // Return some cliched textual content
    	   
		String filename = "/org/agile/grenoble/data/xml/questions.xml";
		String answers ="<hey>questions</hey>"; 
		try {
			QuestionsReader.printItems(filename);
			QuestionsDocument questions = QuestionsReader.getDocument(filename);
			System.out.println("coucou");
			if (all) {
				answers=questions.xmlText() ;
			} else {
				answers="<size>"+questions.getQuestions().getQuestionArray().length +"</size>";
			} //end if 
			System.out.println("coucou");
			//answers=questions.xmlText();
		} catch (Exception e) {
			e.printStackTrace();
		} //end try 
           return answers ; 
       }
}